package sistema;

import java.util.*;

public class SEL {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		System.out.print("n(>=1)=");
		int n = sc.nextInt();
		sc.nextLine();
		double[][] a = new double[n][n];
		double[] y = new double[n];
		System.out.println("Fornisci " + n + "x" + n + " coefficienti");
		for (int i = 0; i < n; i++)
			for (int j = 0; j < n; j++) {
				System.out.print("a[" + i + "][" + j + "]=");
				a[i][j] = sc.nextDouble();
				sc.nextLine();
			}
		System.out.println("Fornisci " + n + " termini noti");

		for (int i = 0; i < n; i++) {
			System.out.print("y[" + i + "]=");
			y[i] = sc.nextDouble();
			sc.nextLine();
		}
		Sistema s = new Gauss(a, y);
		double[] x = null;
		try {
			x = s.risolvi();
		} catch (SistemaSingolare e) {
			System.out.println("Sistema singolare !");
			System.exit(-1);
		}
		// scrivi soluzione
		for (int i = 0; i < n; i++) {
			System.out.printf("X[" + i + "]=%1.2f%n", x[i]);
		}
	}
}
